package com.ccsoft.gsms.model;

import lombok.Data;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @ClassName:UserFuse
 * @Description:TODO
 * @Author:chanchaw
 * @Date:2019-11-25 16:09
 * @Version:1.0
 **/
@Data
@ToString
public class UserFuse implements UserDetails {

    private SysUser sysUser;

    // 用户拥有的所有权限
    private List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return sysUser.getPassword();
    }

    @Override
    public String getUsername() {
        return sysUser.getIid().toString();
    }

    @Override
    public boolean isAccountNonExpired() {
        return sysUser.getNon_expired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return sysUser.getNon_locked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return sysUser.getNon_password_expired();
    }

    @Override
    public boolean isEnabled() {
        if (sysUser.getStatus() == 1) return true;
        return false;
    }
}
